class Solution:
    def countAndSay(self, n: int) -> str:
        s = '1'
        for i in range(n-1):
            t = ''
            j = 0
            while j < len(s):
                k = j + 1
                while k < len(s) and s[j] == s[k]:
                    k += 1
                t += str(k - j) + s[j]
                j = k
            s = t

        return s
